package com.example.homework.homework05;

// 1.定义线程任务类PrinterNumTask，实现Runnable接口
public class PrinterNumTask implements Runnable {
    // 2.定义int类型成员变量num,初始化值为1，代表打印的数字从1开始
    private int num;

    public PrinterNumTask(int num) {
        this.num = num;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                // 如果num大于52，则退出循环
                if (num > 52) {
                    break;
                }
                // 输出num
                System.out.print(num + " ");
                num++;
            }
        }
    }
}
